import 'package:flutter/material.dart';

class CalculatorPage extends StatefulWidget {
  CalculatorPage({Key key, this.title}) : super(key: key);

  final String title;
  @override
  _CalculatorPageState createState() => _CalculatorPageState();
}

class _CalculatorPageState extends State<CalculatorPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Calculator(),
    );
  }
}

class Calculator extends StatelessWidget {
  const Calculator({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Expanded(
          flex: 4,
          child: Text("图片"),
        ),
        Expanded(
          flex: 1,
          child: Text(
            "text",
            textAlign: TextAlign.left,
            style: TextStyle(
              fontSize: 30,
            ),
          ),
        ),
        Expanded(
          flex: 1,
          child: Row(
            children: [
              Expanded(
                child: ElevatedButton(
                  child: Text("C"),
                  onPressed: () {
                    clickKey('c');
                  },
                ),
                flex: 1,
              ),
              SizedBox(
                width: 2,
              ),
              Expanded(
                child: ElevatedButton(
                  child: Text("←"),
                  onPressed: () {},
                ),
                flex: 1,
              ),
              SizedBox(
                width: 2,
              ),
              Expanded(
                child: ElevatedButton(
                  child: Text("%"),
                  onPressed: () {},
                ),
                flex: 1,
              ),
              SizedBox(
                width: 2,
              ),
              Expanded(
                child: ElevatedButton(
                  child: Text("/"),
                  onPressed: () {},
                ),
                flex: 1,
              ),
            ],
          ),
        ),
        Expanded(
          flex: 1,
          child: Row(
            children: [
              Expanded(
                child: ElevatedButton(
                  child: Text("1"),
                  onPressed: () {
                    clickKey('1');
                  },
                ),
                flex: 1,
              ),
              SizedBox(
                width: 2,
              ),
              Expanded(
                child: ElevatedButton(
                  child: Text("2"),
                  onPressed: () {
                    clickKey('2');
                  },
                ),
                flex: 1,
              ),
              SizedBox(
                width: 2,
              ),
              Expanded(
                child: ElevatedButton(
                  child: Text("3"),
                  onPressed: () {
                    clickKey('3');
                  },
                ),
                flex: 1,
              ),
              SizedBox(
                width: 2,
              ),
              Expanded(
                child: ElevatedButton(
                  child: Text("*"),
                  onPressed: () {},
                ),
                flex: 1,
              ),
            ],
          ),
        ),
        Expanded(
          flex: 1,
          child: Row(
            children: [
              Expanded(
                child: ElevatedButton(
                  child: Text("4"),
                  onPressed: () {},
                ),
                flex: 1,
              ),
              SizedBox(
                width: 2,
              ),
              Expanded(
                child: ElevatedButton(
                  child: Text("5"),
                  onPressed: () {},
                ),
                flex: 1,
              ),
              SizedBox(
                width: 2,
              ),
              Expanded(
                child: ElevatedButton(
                  child: Text("6"),
                  onPressed: () {},
                ),
                flex: 1,
              ),
              SizedBox(
                width: 2,
              ),
              Expanded(
                child: ElevatedButton(
                  child: Text("-"),
                  onPressed: () {},
                ),
                flex: 1,
              ),
            ],
          ),
        ),
        Expanded(
          flex: 1,
          child: Row(
            children: [
              Expanded(
                child: ElevatedButton(
                  child: Text("7"),
                  onPressed: () {},
                ),
                flex: 1,
              ),
              SizedBox(
                width: 2,
              ),
              Expanded(
                child: ElevatedButton(
                  child: Text("8"),
                  onPressed: () {},
                ),
                flex: 1,
              ),
              SizedBox(
                width: 2,
              ),
              Expanded(
                child: ElevatedButton(
                  child: Text("9"),
                  onPressed: () {},
                ),
                flex: 1,
              ),
              SizedBox(
                width: 2,
              ),
              Expanded(
                child: ElevatedButton(
                  child: Text("+"),
                  onPressed: () {},
                ),
                flex: 1,
              ),
            ],
          ),
        ),
        Expanded(
          flex: 1,
          child: Row(
            children: [
              Expanded(
                child: ElevatedButton(
                  child: Text("."),
                  onPressed: () {},
                ),
                flex: 1,
              ),
              SizedBox(
                width: 2,
              ),
              Expanded(
                child: ElevatedButton(
                  child: Text("0"),
                  onPressed: () {},
                ),
                flex: 1,
              ),
              SizedBox(
                width: 2,
              ),
              Expanded(
                child: ElevatedButton(
                  child: Text("="),
                  onPressed: () {},
                ),
                flex: 2,
              ),
            ],
          ),
        ),
      ],
    );
  }

  void clickKey(String key) {
    print(key);
  }
}
